home *** CD-ROM | disk | FTP | other *** search
- ;**************************************************************
- ;
- ; sqrt_opt.asm
- ;
- ; staff
- ;
- ; 04-19-91
- ;
- ; (C) Texas Instruments Inc., 1992
- ;
- ; Refer to the file 'license.txt' included with this
- ; this package for usage and license information.
- ;
- ;**************************************************************
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Square Root Computation
- ;
- ; This routine computes square root of a number that is located
- ; in the lower half of accumulator. The number is in Q15 format.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- BRCR .set 09h ;DP=0
- ST0 .set 60h ;Internal RAM block B2
- ST1 .set 61h
- NUMBER .set 62h
- TEMPR .set 63h
- GUESS .set 64h
-
- .text
- SQRT SST #0,ST0
- SST #1,ST1 ;Save context
- LDP #0
- SETC SXM ;Set SXM=1
- SPM 1 ;Set PM mode for fractional arithmetic
- SACL NUMBER ;Save the number
- LACC #0
- SACB ;Clear Accumulator Buffer
- SPLK #11,BRCR ;initialize for 12 iterations
- SPLK #800h,GUESS ;Set initial guess
- LACC NUMBER
- SUB #200h
- BCNDD LOOP,LT ;If NUMBER<200h then begin looping
- SPLK #800h,TEMPR
- LACC #4000h ;Otherwise set initial guess
- SACL GUESS ;and temporary root to 4000h
- SACL TEMPR
- SPLK #14,BRCR ;and increase iterations to 15
-
- LOOP RPTB ENDLP-1 ;Repeat block
- SQRA TEMPR ;Square temporary root
- LACC NUMBER,16
- SPAC ;Acc=NUMBER-TEMPR**2
- NOP ;Dead cycle for XC
- XC 2,GT ;If NUMBER>TEMPR**2 skip next 2 instr.
- LACC TEMPR,16
- SACB ;Otherwise ROOT <- TEMPR
- LACC GUESS,15
- SACH GUESS ;GUESS <- GUESS/2
- ADDB
- SACH TEMPR ;TEMPR <- GUESS+ROOT
-
- ENDLP LACB ;High Acc contains square root of NUMBER
- RETD
- LST #0,ST0
- LST #1,ST1 ;Restore context